﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Barbar.Colonization.Model {
  public class World {
    private Hashtable m_Tiles = new Hashtable(30000, 0.3f);
    private IRuleSet m_RuleSet;
    private int m_Width;
    private int m_Height;

    public int Width {
      get { return m_Width; }
    }

    public int Height {
      get { return m_Height; }
    }

    internal World(IRuleSet ruleSet, int width, int height) {
      if (ruleSet == null)
        throw new ArgumentNullException("ruleSet");
      if (width < Constants.MinWorldWidth || width > Constants.MaxWorldWidth)
        throw new ArgumentOutOfRangeException("width");
      if (height < Constants.MinWorldHeight || height > Constants.MaxWorldHeight)
        throw new ArgumentOutOfRangeException("height");

      m_RuleSet = ruleSet;
      m_Width = width;
      m_Height = height;

      ITileType defaultTileType = m_RuleSet.TileTypes.DefaultTileType;
      for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
          Coordinate coordinate = new Coordinate(x, y);
          m_Tiles.Add(coordinate, defaultTileType.CreateEmptyTile(coordinate));
        }
    }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1043:UseIntegralOrStringArgumentForIndexers")]
    public Tile this[Coordinate coordinate] {
      get { return (Tile)m_Tiles[coordinate]; }
      internal set { m_Tiles[coordinate] = value; }
    }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1023:IndexersShouldNotBeMultidimensional")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "y")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "x")]
    public Tile this[int x, int y] {
      get { return this[new Coordinate(x, y)]; }
      internal set { this[new Coordinate(x, y)] = value; }
    }
  }
}
